#ifndef GAME_H
#define GAME_H

#include "Singleton.h"

#include <QDebug>
#include <QList>
#include <QMap>

class Content;
class VariableExp;


class Content {
  public:
    bool Lookup(QString s) const
    {
        return _map.value(s);
    }
    void Assign(VariableExp* v, bool b);
private:
    QMap<QString, bool> _map;
};


class BooleanExp {
public:
    BooleanExp(){}
    virtual ~BooleanExp(){}

    virtual bool Evaluate(Content&) = 0;
    virtual BooleanExp* Copy() const = 0;
};

class Contant: public BooleanExp {
public:
    Contant(bool b){ _b = b; }
    virtual ~Contant(){}

    virtual bool Evaluate(Content&){
        return _b;
    }
    virtual BooleanExp* Copy() const
    {
        return new Contant(_b);
    }
private:
    bool _b;
};

class VariableExp: public BooleanExp {
  public:
    VariableExp(QString s)
    {
        _name = s;
    }
    virtual ~VariableExp(){}
    virtual bool Evaluate(Content &aContent)
    {
        return aContent.Lookup(_name);
    }
    virtual BooleanExp* Copy() const
    {
        return new VariableExp(_name);
    }
    virtual QString Name(){ return _name; }
private:
    QString _name;
};

class AndExp: public BooleanExp {
  public:
    AndExp(BooleanExp* b1, BooleanExp* b2):_operand1(b1),_operand2(b2){}
    virtual ~AndExp(){}

    virtual bool Evaluate(Content &aContent){
        return _operand1->Evaluate(aContent) && _operand2->Evaluate(aContent);
    }
    virtual BooleanExp* Copy() const
    {
        return new AndExp(_operand1->Copy(), _operand2->Copy());
    }
private:
    BooleanExp* _operand1;
    BooleanExp* _operand2;
};



#endif // GAME_H
